<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul>
        <li>八戒</li>
        <li>悟空</li>
        <li>唐僧</li>
        <li>沙僧</li>
    </ul>
    <script>
        // function onter(){
        //     var num = 100;
        //     function inner(){
        //        num = 10
        //     }
        //     inner()
        // }
        // onter()
        var list = document.querySelectorAll("li")
        for (var i = 0; i < list.length; i++) {
            list[i].onclick = function () {
                console.log(this.innerHtml);
            }
        }

        var car = (function () {
                var start = 13;// 起步价
                var total = 0; // 总价
                // 正常打车计费
                return{
                    price: function(n) {
                    if (n >= 3) {
                        return total = start + (n - 3) * 5
                    } else {
                        return total;
                    }
                },
                // 堵车计费
                yd: function(flag) {
                    return flag ? total + 10 : total;
                }

                }
            })();
        console.log( car.price(5));
        console.log(car.yd(true));

        console.log(car.price(3));
        console.log(car.yd(false ));

    </script>
</body>

</html>